from django.test import TestCase

# Create your tests here.
a = {'errcode': 0, 'errmsg': 'ok', 'info': {'sp_no': '202312300136', 'sp_name': '测试', 'sp_status': 1,
                                            'template_id': 'C4WopLCXnyAD9na8t2erMcLEsvcusrQvwyYL2Ycfh',
                                            'apply_time': 1703944775, 'applyer': {'userid': 'LiDong', 'partyid': '1'},
                                            'sp_record': [{'sp_status': 1, 'approverattr': 1, 'details': [
                                                {'approver': {'userid': 'YuChi'}, 'speech': '', 'sp_status': 1,
                                                 'sptime': 0, 'media_id': []},
                                                {'approver': {'userid': 'LiDong'}, 'speech': '', 'sp_status': 1,
                                                 'sptime': 0, 'media_id': []}]}, {'sp_status': 1, 'approverattr': 1,
                                                                                  'details': [{'approver': {
                                                                                      'userid': 'FengZhiYiNanPing'},
                                                                                               'speech': '',
                                                                                               'sp_status': 1,
                                                                                               'sptime': 0,
                                                                                               'media_id': []}]}],
                                            'notifyer': [{'userid': 'LiDong'}], 'apply_data': {'contents': [
        {'control': 'Text', 'id': 'Text-1703726478834', 'title': [{'text': '店铺id', 'lang': 'zh_CN'}],
         'value': {'text': '235', 'tips': [], 'members': [], 'departments': [], 'files': [], 'children': [],
                   'stat_field': [], 'sum_field': [], 'related_approval': [], 'students': [], 'classes': [], 'docs': [],
                   'wedrive_files': []}, 'display': 1, 'require': 1},
        {'control': 'Text', 'id': 'Text-1703726501363', 'title': [{'text': '店铺名称', 'lang': 'zh_CN'}],
         'value': {'text': '看看', 'tips': [], 'members': [], 'departments': [], 'files': [], 'children': [],
                   'stat_field': [], 'sum_field': [], 'related_approval': [], 'students': [], 'classes': [], 'docs': [],
                   'wedrive_files': []}, 'display': 1, 'require': 1},
        {'control': 'Text', 'id': 'Text-1703726617125', 'title': [{'text': '收货人', 'lang': 'zh_CN'}],
         'value': {'text': '娱乐', 'tips': [], 'members': [], 'departments': [], 'files': [], 'children': [],
                   'stat_field': [], 'sum_field': [], 'related_approval': [], 'students': [], 'classes': [], 'docs': [],
                   'wedrive_files': []}, 'display': 1, 'require': 1},
        {'control': 'Selector', 'id': 'Selector-1703726571219', 'title': [{'text': '是否公司安装', 'lang': 'zh_CN'}],
         'value': {'tips': [], 'members': [], 'departments': [], 'files': [], 'children': [], 'stat_field': [],
                   'selector': {'type': 'single', 'options': [
                       {'key': 'option-1703726571220', 'value': [{'text': '是', 'lang': 'zh_CN'}]}],
                                'op_relations': []}, 'sum_field': [], 'related_approval': [], 'students': [],
                   'classes': [], 'docs': [], 'wedrive_files': []}, 'display': 1, 'require': 1},
        {'control': 'Selector', 'id': 'Selector-1702538399169', 'title': [{'text': '监控选择', 'lang': 'zh_CN'}],
         'value': {'tips': [], 'members': [], 'departments': [], 'files': [], 'children': [], 'stat_field': [],
                   'selector': {'type': 'single', 'options': [
                       {'key': 'option-1702538399170', 'value': [{'text': '高清摄像头', 'lang': 'zh_CN'}]}],
                                'op_relations': []}, 'sum_field': [], 'related_approval': [], 'students': [],
                   'classes': [], 'docs': [], 'wedrive_files': []}, 'display': 1, 'require': 1},
        {'control': 'Selector', 'id': 'Selector-1702547197528', 'title': [{'text': '定制品', 'lang': 'zh_CN'}],
         'value': {'tips': [], 'members': [], 'departments': [], 'files': [], 'children': [], 'stat_field': [],
                   'selector': {'type': 'single', 'options': [
                       {'key': 'option-1702547197530', 'value': [{'text': '无', 'lang': 'zh_CN'}]}],
                                'op_relations': []}, 'sum_field': [], 'related_approval': [], 'students': [],
                   'classes': [], 'docs': [], 'wedrive_files': []}, 'display': 1, 'require': 0},
        {'control': 'Selector', 'id': 'Selector-1702547226160', 'title': [{'text': '摄像头', 'lang': 'zh_CN'}],
         'value': {'tips': [], 'members': [], 'departments': [], 'files': [], 'children': [], 'stat_field': [],
                   'selector': {'type': 'single', 'options': [], 'op_relations': []}, 'sum_field': [],
                   'related_approval': [], 'students': [], 'classes': [], 'docs': [], 'wedrive_files': []}, 'hidden': 1,
         'display': 1, 'require': 0},
        {'control': 'Number', 'id': 'Number-1702547288240', 'title': [{'text': '数量', 'lang': 'zh_CN'}],
         'value': {'tips': [], 'members': [], 'departments': [], 'files': [], 'children': [], 'stat_field': [],
                   'new_number': '', 'sum_field': [], 'related_approval': [], 'students': [], 'classes': [], 'docs': [],
                   'wedrive_files': []}, 'hidden': 1, 'display': 1, 'require': 0},
        {'control': 'Money', 'id': 'Money-1702549874218', 'title': [{'text': '应付金额', 'lang': 'zh_CN'}],
         'value': {'tips': [], 'members': [], 'departments': [], 'files': [], 'children': [], 'stat_field': [],
                   'new_money': '122', 'sum_field': [], 'related_approval': [], 'students': [], 'classes': [],
                   'docs': [], 'wedrive_files': []}, 'display': 1, 'require': 0},
        {'control': 'Money', 'id': 'Money-1702549875825', 'title': [{'text': '实付价格', 'lang': 'zh_CN'}],
         'value': {'tips': [], 'members': [], 'departments': [], 'files': [], 'children': [], 'stat_field': [],
                   'new_money': '123', 'sum_field': [], 'related_approval': [], 'students': [], 'classes': [],
                   'docs': [], 'wedrive_files': []}, 'display': 1, 'require': 0},
        {'control': 'Tips', 'id': 'Tips-1703755070827', 'title': [{'text': '说明', 'lang': 'zh_CN'}],
         'value': {'tips': [], 'members': [], 'departments': [], 'files': [], 'children': [], 'stat_field': [],
                   'sum_field': [], 'related_approval': [], 'students': [], 'classes': [], 'docs': [],
                   'wedrive_files': []}, 'display': 1, 'require': 0}]}, 'comments': []}}



user_id = 'LiDong'
step = 1
approverattr = 1

a_time = 0
max_value = 0

sp_record = a['info']['sp_record']
# 遍历步数
for record in sp_record:
    print(record)
    details = record['details']
    step_status = record['sp_status']
    for detail in details:
        userid = detail['approver']['userid']
        user_speech = detail['speech']
        user_status = detail['sp_status']
        user_sptime = detail['sptime']
        user_media_id = detail['media_id']
        max_value = max(max_value, user_sptime)
        if userid == user_id:
            a_time = user_sptime
            a_status = user_status

if a_time == max_value and a_time != 0:
    print('开始导入数据')
